package ch.fhnw.kosmonauten.client.core;

import java.util.Random;

/**
 * Diese Klasse erstellt einen Request.
 * 
 * @author Fabian Siegrist
 * @author Oliver Freiermuth
 * @author Mikhail Onoufrienko
 * @author Risto Milani
 * @version $Revision: 154 $
 *          File name: $HeadURL: http://iching-kosmonauten.googlecode.com/svn/I-Ching/src/ch/fhnw/kosmonauten/client/core/Utility.java $
 *          Last modified:$Date: 2013-05-26 02:43:14 +0000 (Sun, 26 May 2013) $
 *          Last modified by: $Author: molotok.mihon@gmail.com $
 */

// class definition
public class Utility {

	// methods
	/**
	 * @param start
	 * @param stop
	 * @param count
	 * @return
	 */
	public static int[] generateRandom(int start, int stop, int count) {
		int[] numbers = new int[count];
		Random random = new Random();
		long range;
		long fraction;
		if (start > stop) {
			throw new IllegalArgumentException("Start cannot exceed End.");
		}
		// get the range, casting to long to avoid overflow problems
		for (int i = 0; i < count; i++) {
			range = (long) stop - (long) start + 1;
			fraction = (long) (range * random.nextDouble());
			numbers[i] = (int) (fraction + start);
		}
		return numbers;
	}
	
	public static int[] convertStringToArray (String toarray)
	{
		try
		{
			int[] intArray = new int[toarray.length()];
			char [] asChar = toarray.toCharArray();
			int i=0;
			for (char c : asChar) {
				intArray[i++] = Character.digit(c,10);
			}
			return intArray;
		}
		catch(Exception e){
			return null;
		}
		
	}

}
